package com.worldtolearn.offer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;

import com.worldtolearn.comment.bu.CommentBu;
import com.worldtolearn.comment.dao.CommentDAO;
import com.worldtolearn.comment.dao.CommentDAOImpl;
import com.worldtolearn.comment.entity.Comment;
import com.worldtolearn.offer.bu.AdressBu;
import com.worldtolearn.offer.bu.OfferBu;
import com.worldtolearn.offer.bu.RateBu;
import com.worldtolearn.offer.bu.SupplierOfferBu;
import com.worldtolearn.offer.entity.Activity;
import com.worldtolearn.offer.entity.Adress;
import com.worldtolearn.offer.entity.Description;
import com.worldtolearn.offer.entity.Offer;
import com.worldtolearn.offer.entity.Period;
import com.worldtolearn.offer.entity.Price;
import com.worldtolearn.offer.entity.Rate;
import com.worldtolearn.offer.entity.SupplierOffer;
import com.worldtolearn.user.entity.Person;
//
@RunWith(SpringJUnit4ClassRunner.class)
//@TestExecutionListeners(value = { DependencyInjectionTestExecutionListener.class })
//@ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/springConf.xml" })
//@ContextConfiguration(locations = { "classpath:/springConf.xml" })//celle qui marche
//@ContextConfiguration(locations={"springConf.xml"})
//@ContextConfiguration(locations = { "file:src/test/resources/springConf.xml" })
public class CreateOffer {
//	private static ClassPathXmlApplicationContext context;



	@Autowired
	AdressBu adressBu;
	
	@Autowired
	private ApplicationContext context;

	@Autowired
	SupplierOfferBu supplierOfferBu;

	@Autowired
	OfferBu offerBu;
	
	@Autowired
	CommentBu ctBu;
	
	@Autowired
	CommentDAO ctDao;
	
	@Autowired
	RateBu rateBu;
	
	List<Adress> listAdress;
	List<String> listPays;
	

//	@Before
//	public void init() {
//		 ApplicationContext context = new
//		 ClassPathXmlApplicationContext("file:src/main/webapp/WEB-INF/springConf.xml");
//		 ctBu = (CommentBu)context.getBean("ctBu");
//		context = new ClassPathXmlApplicationContext("springConf.xml");
//	    ctBu = (CommentBu)context.getBean("ctBu");
//	}
//	ApplicationContext ctx =
//		    new FileSystemXmlApplicationContext("file:src/main/webapp/WEB-INF/springConf.xml");
	ApplicationContext ctx =
		    new ClassPathXmlApplicationContext("classpath*:springConf.xml");
//	 ApplicationContext ctx = new ClassPathXmlApplicationContext("META-INF/springConf.xml");

	
	@Test
	public void commentTest() {

		 CommentDAO ctDao = ctx.getBean("accountDao", CommentDAOImpl.class);
//		ctDao = (CommentDAO)context.getBean("commentDAOImpl");
		 ctBu = (CommentBu)context.getBean("commentBu");
		Person p = new Person();
		Comment c = new Comment();
		c.setComment("toto");
		
		c.setPerson(p);
		System.out.println("cccccccccccccc :"+c);
		ctDao.addComment(c);
//		ctBu.addComment(c);
	}
//	
//	@Test
//	public void name() {
//		listPays = adressBu.getDistinctAdresse();
//		System.out.println("$$$$$$$$$$$$$$$$$$$$$$ " + listAdress.size()
//				+ " pays différents");
//		System.out.println(listPays.get(0));
//		for (String ad : listPays) {
//			System.out.println("liste des pays : " + ad.toString());
//		}
//	}
//	
//	@Test
//	public void createNewOffer() throws ParseException {
//		
//		String date = "01/09/2013";
//		SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");		
//		String date15 = "08/09/2013";
//		SimpleDateFormat sdf15 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date2 = "05/09/2013";
//		SimpleDateFormat sdf2 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date16 = "12/09/2013";
//		SimpleDateFormat sdf16 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date3 = "15/09/2013";
//		SimpleDateFormat sdf3 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date17 = "22/09/2013";
//		SimpleDateFormat sdf17 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date4 = "20/09/2013";
//		SimpleDateFormat sdf4 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date18 = "27/09/2013";
//		SimpleDateFormat sdf18 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date5 = "25/09/2013";
//		SimpleDateFormat sdf5 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date19 = "02/10/2013";
//		SimpleDateFormat sdf19 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date6 = "26/09/2013";
//		SimpleDateFormat sdf6 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date20 = "03/10/2013";
//		SimpleDateFormat sdf20 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date7 = "27/09/2013";
//		SimpleDateFormat sdf7 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date21 = "04/10/2013";
//		SimpleDateFormat sdf21 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date8 = "28/09/2013";
//		SimpleDateFormat sdf8 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date22 = "05/10/2013";
//		SimpleDateFormat sdf22 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date9 = "29/09/2013";
//		SimpleDateFormat sdf9 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date23 = "06/10/2013";
//		SimpleDateFormat sdf23 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date10 = "30/09/2013";
//		SimpleDateFormat sdf10 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date24 = "07/10/2013";
//		SimpleDateFormat sdf24 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date11 = "01/10/2013";
//		SimpleDateFormat sdf11 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date25 = "08/10/2013";
//		SimpleDateFormat sdf25 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date12 = "02/10/2013";
//		SimpleDateFormat sdf12 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date26 = "09/10/2013";
//		SimpleDateFormat sdf26 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date13 = "03/10/2013";
//		SimpleDateFormat sdf13 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date27 = "10/10/2013";
//		SimpleDateFormat sdf27 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date14 = "04/10/2013";
//		SimpleDateFormat sdf14 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date28 = "11/10/2013";
//		SimpleDateFormat sdf28 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		String date29 = "05/10/2013";
//		SimpleDateFormat sdf29 = new SimpleDateFormat("dd/MM/yyyy");		
//		String date30 = "12/10/2013";
//		SimpleDateFormat sdf30 = new SimpleDateFormat("dd/MM/yyyy");
//		
//		
//			Date dateDebut1 = sdf.parse(date);
//			Date dateDebut2 = sdf2.parse(date2);
//			Date dateDebut3 = sdf3.parse(date3);
//			Date dateDebut4 = sdf4.parse(date4);
//			Date dateDebut5 = sdf5.parse(date5);
//			Date dateDebut6 = sdf6.parse(date6);
//			Date dateDebut7 = sdf7.parse(date7);
//			Date dateDebut8 = sdf8.parse(date8);
//			Date dateDebut9 = sdf9.parse(date9);
//			Date dateDebut10 = sdf10.parse(date10);
//			Date dateDebut11 = sdf11.parse(date11);
//			Date dateDebut12 = sdf12.parse(date12);
//			Date dateDebut13 = sdf13.parse(date13);
//			Date dateDebut14 = sdf14.parse(date14);
//			Date dateDebut15 = sdf29.parse(date29);
//			
//			Date datefin1 = sdf15.parse(date15);
//			Date datefin2 = sdf16.parse(date16);
//			Date datefin3 = sdf17.parse(date17);
//			Date datefin4 = sdf18.parse(date18);
//			Date datefin5 = sdf19.parse(date19);
//			Date datefin6 = sdf20.parse(date20);
//			Date datefin7 = sdf21.parse(date21);
//			Date datefin8 = sdf22.parse(date22);
//			Date datefin9 = sdf23.parse(date23);
//			Date datefin10 = sdf24.parse(date24);
//			Date datefin11 = sdf25.parse(date25);
//			Date datefin12 = sdf26.parse(date26);
//			Date datefin13 = sdf27.parse(date27);
//			Date datefin14 = sdf28.parse(date28);
//			Date datefin15 = sdf30.parse(date30);
//		
//		
//		
//		Offer offer = new Offer("Stage de Samba à Bahia - Brésil", 
//				new SupplierOffer(new Activity("Loisirs", "Danse"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Brésil"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/samba.jpg", "templates/img/imgMini/samba2.jpg")),
//						new Rate(new Price(750, 19, 20),new Period(dateDebut1, datefin1)));
//		
////		Offer offer2 = new Offer("Apprendre l'Archerie à Oulan-Bator - Mongolie", 
////				new SupplierOffer(new Activity("Métier", "Archerie"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Mongolie"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/fleche.jpg", "templates/img/imgMini/fleche2.jpg")),
////						new Rate(new Price(300, 19, 20),new Period(dateDebut2, datefin2)));
//		
////		Offer offer3 = new Offer("Médecine Traditionnelle à Pekin - Chine", 
////				new SupplierOffer(new Activity("Loisirs", "Santé"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Chine"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/corps.jpg","templates/img/imgMini/corps2.jpg" )),
////						new Rate(new Price(950, 19, 20),new Period(dateDebut3, datefin3)));
//		
////		Offer offer4 = new Offer("Apprendre la Pâtisserie à Paris - France", 
////				new SupplierOffer(new Activity("Métier", "Culinaire"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "France"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/patisserie.jpg", "templates/img/imgMini/patisserie2.jpg")),
////						new Rate(new Price(1200, 19, 20),new Period(dateDebut4, datefin4)));
//		
//		Offer offer5 = new Offer("Stage de Base Jump à  Oslo - Norvège", 
//				new SupplierOffer(new Activity("Loisir", "Extrême"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Norvège"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/base.jpg", "templates/img/imgMini/base2.jpg")),
//						new Rate(new Price(650, 19, 20),new Period(dateDebut5, datefin5)));
//		
////		Offer offer6 = new Offer("Atelier poésie à Selfoss - Islande", 
////				new SupplierOffer(new Activity("Loisir", "Ecriture"),
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Islande"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/plume.jpeg", "templates/img/imgMini/plume2.jpg")),
////						new Rate(new Price(400, 19, 20),new Period(dateDebut6, datefin6)));
//		
////		Offer offer7 = new Offer("Elevage de crevette à Quito - Equateur", 
////				new SupplierOffer(new Activity("Loisir", "Culinaire"),
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Equateur"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "crevette.jpg", "templates/img/imgMini/crevette2.jpg")),
////						new Rate(new Price(550, 19, 20),new Period(dateDebut7, datefin7)));
//		
//		Offer offer8 = new Offer("Stage de Capoeira à Rio de Janeiro - Brésil", 
//				new SupplierOffer(new Activity("Loisir", "Danse"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Brésil"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/capoeira.jpg", "templates/img/imgMini/capoeira2.jpg")),
//						new Rate(new Price(450, 19, 20),new Period(dateDebut8, datefin8)));
//		
////		Offer offer9 = new Offer("Stage de parachutisme en Corse", 
////				new SupplierOffer(new Activity("Loisir", "Extrême"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "France"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/parachutisme.jpg", "templates/img/imgMini/parachutisme2.jpg")),
////						new Rate(new Price(950, 19, 20),new Period(dateDebut9, datefin9)));
//		
////		Offer offer10 = new Offer("Stage Maquillage pour effets speciaux à Hollywood", 
////				new SupplierOffer(new Activity("Loisir", "Esthétique"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Etat-Unis"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/pinceau.jpg", "templates/img/imgMini/pinceau2.jpg")),
////						new Rate(new Price(1000, 19, 20),new Period(dateDebut10, datefin10)));
//		
//		Offer offer11 = new Offer("Stage de Kite Surf à Tibau do Sul - Brésil", 
//				new SupplierOffer(new Activity("Loisir", "Extrême"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Brésil"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/kite.jpg", "templates/img/imgMini/kite2.jpg")),
//						new Rate(new Price(850, 19, 20),new Period(dateDebut11, datefin11)));
//		
//		Offer offer12 = new Offer("Stage de kung-fu à Shanghai", 
//				new SupplierOffer(new Activity("Loisir", "Art martiaux"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Chine"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/kungfu.jpg", "templates/img/imgMini/kungfu2.jpg")),
//						new Rate(new Price(750, 19, 20),new Period(dateDebut12, datefin12)));
//		
////		Offer offer13 = new Offer("Stage de cuisine à Paris - France", 
////				new SupplierOffer(new Activity("Loisir", "Culinaire"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "France"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/cuisine.jpg", "templates/img/imgMini/cuisine2.jpg")),
////						new Rate(new Price(1100, 19, 20),new Period(dateDebut13, datefin13)));
////		
////		Offer offer14 = new Offer("Safari à Nairobi - Kenya - Afrique du Sud", 
////				new SupplierOffer(new Activity("Loisir", "Excursion"), 
////						new Adress("3", "rue Danton", "12345", "Malakoff", "Kenya"),
////						new Description("Haec igitur Epicuri non probo, inquam."
////								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
////								+ "instructior est enim, quod tibi ita videri necesse est, "
////								+ "non satis politus iis artibus, quas qui tenent, eruditi"
////								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
////								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/safari.jpg","templates/img/imgMini/safari2.jpg")),
////						new Rate(new Price(1600, 19, 20),new Period(dateDebut14, datefin14)));
//		
//		Offer offer15 = new Offer("Apprendre la guitare à New York - Etat-Unis", 
//				new SupplierOffer(new Activity("Métier", "Musique"), 
//						new Adress("3", "rue Danton", "12345", "Malakoff", "Etat-Unis"),
//						new Description("Haec igitur Epicuri non probo, inquam."
//								+ " De cetero vellem equidem aut ipse doctrinis fuisset "
//								+ "instructior est enim, quod tibi ita videri necesse est, "
//								+ "non satis politus iis artibus, quas qui tenent, eruditi"
//								+ " appellantur aut ne deterruisset alios a studiis. quamquam"
//								+ " te quidem video minime esse deterritum.", "templates/img/imgOffre/guitare.JPG", "templates/img/imgMini/guitare2.jpg")),
//						new Rate(new Price(760, 19, 20),new Period(dateDebut15, datefin15)));
//		
//		
//		offerBu.createOffer(offer);
////		offerBu.createOffer(offer2);	
////		offerBu.createOffer(offer3);	
////		offerBu.createOffer(offer4);	
//		offerBu.createOffer(offer5);		
////		offerBu.createOffer(offer6);		
////		offerBu.createOffer(offer7);		
//		offerBu.createOffer(offer8);		
////		offerBu.createOffer(offer9);		
////		offerBu.createOffer(offer10);		
//		offerBu.createOffer(offer11);		
//		offerBu.createOffer(offer12);		
////		offerBu.createOffer(offer13);		
////		offerBu.createOffer(offer14);		
//		offerBu.createOffer(offer15);
//		
//	}
//	
//	@Test
//	public void getOfferById() {
//		List<Offer> list  = offerBu.getOfferById(1);
//		System.out.println(list.get(0).getLabelOffer());
//	}
}
